<?php
namespace Admin\Controller;
//use Think\Controller;
class UserController extends CommontController {
	//用户添加
    public function add(){
    	$userModel=D('User');
    	// dump($userModel);die;
    	if(IS_POST){
    		if($userModel->create()){
    			if($userModel->add()){
    				$this->success('添加成功',U('User/index'));die;
    			}else{
    				$this->error("添加失败");
    			}
    		}else{
    			$this->error($userModel->getError());
    		}
    	}
        $this->display();
    }
    //用户列表
    public function index(){
    	$userModel=D('User');
        //分页操作
        $count=$userModel->count();
        $page=new \Think\Page($count,3);
        $page->setConfig('prev','上一页');
        $page->setConfig('next','下一页');
        $this->pageList=$page->show();
        $this->data=$userModel->order('user_id desc')->limit($page->firstRow.','.$page->listRows)->select();
    	$this->display();
    }
    //用户修改
    public function upd(){
        $userModel=D('User');
        if(IS_POST){
            if($userModel->create()){
                if($userModel->save()!==false){
                    $this->success("修改成功",U('User/index'));die;
                }else{
                    $this->error("修改失败");
                }
            }else{
                $this->error($userModel->getError());
            }
        }
        $user_id=I("get.user_id");
        $data=$userModel->find($user_id);
        $this->assign('data',$data);
        $this->display();
    }
    //用户删除
    public function del(){
        $userModel=D('User');
        $user_id=I('get.user_id');
        $data=$userModel->delete($user_id);
        if($data){
            $this->success("删除成功",U("User/index"));die;
        }else{
            $this->error("删除失败");
        }
    }
}